/*Hdip Project 2013-14, Student Name:- Chris Pembroke,  Student Number:- x00115839*/

using Microsoft.AspNet.Identity.EntityFramework;
using System.ComponentModel.DataAnnotations;      // added namespace declaration for validations

namespace Exercise1Project.Models
{
    // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more.
    public class ApplicationUser : IdentityUser
    {
       
        public string Role { get; set; }

        [Required]
        public string Name { get; set; }

        [Required]
        public string Address { get; set; }

        [Required]
        public string Email { get; set; }

        [Required]
        public string Phone { get; set; }

        public string setUserRole(string username)
        {
            // check if user name is a customer or an shop admin
            if (username.IndexOf("-admin") != -1)     // if user is admin then set role to administrator (word '-admin' will have been appended to the name)
            {
                return "Administrator";
            }
            else                               // if user is a customer set role to customer
            {
                return "Customer";
            }
        }

    }

    public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
    {
        public ApplicationDbContext()
            : base("bikeservice")       // the name added here is the name of the required connection to database from the webconfig file
        {
        }

        
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder) // test example method added so as to change the default table names and id column
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Entity<IdentityUser>().ToTable("Users");
            modelBuilder.Entity<ApplicationUser>().ToTable("Users");
            modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles");
            modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins");
            modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims");
            modelBuilder.Entity<IdentityRole>().ToTable("Roles");
        }
  

    } // close of class applicationdbcontext
} // close of namespace
